<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" />
		<link rel="stylesheet" th:href="@{/css/Site.css}" />
		<link rel="stylesheet" th:href="@{/css/zy.all.css}" />
		<link rel="stylesheet" th:href="@{/css/font-awesome.min.css}" />
		<link rel="stylesheet" th:href="@{/css/amazeui.min.css}" />
		<link rel="stylesheet" th:href="@{/css/admin.css}" />
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
		<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
		<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	</head>

	<body>
		<div class="dvcontent">

			<div>
				<!--tab start-->
				<div class="tabs">
					<div class="hd">
						<ul>
							<li class="on" style="box-sizing: initial;-webkit-box-sizing: initial;">库存管理</li>
							 <li class="" style="box-sizing: initial;-webkit-box-sizing: initial;">添加药品</li>
						</ul>
					</div>
					<div class="bd">
						<ul style="display: block;padding: 20px;">
							<li>
								<!--分页显示角色信息 start-->
								<div id="dv1">
									<table class="table" id="tbRecord">
										<thead>
											<tr>
												<th>药品编号</th>
												<th>药品名称</th>
												<th>药品数量</th>
												<th>编辑</th>
												<th>删除</th>
												
											</tr>
										</thead>
										<tbody>
											<tr th:each="recordInfo:${recordInformations}">
												<td th:text="${recordInfo.medicine.medicineId}">1</td>
												<td th:text="${recordInfo.medicine.name}">罗红霉素分散片</td>
												 
												<td th:text="${recordInfo.inventory.inventory}">1500</td>
												<td class="edit"><button data-toggle="modal" data-target="#myModal"><i class="icon-edit bigger-120"></i>编辑</button></td>
												<!-- 模态框（Modal） -->
												<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
													<div class="modal-dialog">
														<div class="modal-content">
															<div class="modal-header">
																<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
																	&times;
																</button>
																<div class="modal-title" id="myModalLabel">
																	<h4>库存信息修改</h4>
																	<!--<h5 th:text="${recordInfo.medicine.medicineId}"></h5><h5 th:text="${recordInfo.medicine.name}"></h5><h5 th:text="${recordInfo.inventory.inventory}"></h5>-->
																</div>
															</div>
															<!--<form th:action="'/editInventory?id='+${recordInfo.medicine.medicineId}" method="get">-->

															<div class="modal-body">
																<div class="am-form-group">
																	<label for="name" class="am-u-sm-3 am-form-label">
																		药品数量</label>
																	<div class="am-u-sm-9">
																		<input type="text" required id="inventory"
																			   placeholder="药品数量" name="inventory">
																	</div>
																</div>
															</div>
															<div class="modal-footer">
																<button type="button" class="btn btn-default" data-dismiss="modal">关闭
																</button>
																<button type="button" class="btn btn-primary"  onclick="btn_edit(this)" th:data="${recordInfo.medicine.medicineId}">
																	提交更改
																</button>
															</div>
														</div><!-- /.modal-content -->
													</div><!-- /.modal -->
												</div>
												<td class="delete"><button class="btn-delete" th:data="${recordInfo.medicine.medicineId}"><i class="icon-trash bigger-120"></i>删除</button></td>
											</tr>
											<!--onclick="btn_delete(1)"-->
											
											
										</tbody>
									
									</table>
								</div>
								<!--分页显示角色信息 end-->
							</li>
						</ul>
						<ul class="theme-popbod dform" style="display: none;">
								<div class="am-cf admin-main" style="padding-top: 0px;">
			<!-- content start -->
			
	<div class="am-cf admin-main" style="padding-top: 0px;">
		<!-- content start -->
		<div class="admin-content">
			<div class="admin-content-body">
				
				<div class="am-g">
					<div class="am-u-sm-12 am-u-md-4 am-u-md-push-8">
						
					</div>
					<div class="am-u-sm-12 am-u-md-8 am-u-md-pull-4"
						style="padding-top: 30px;">
						<form class="am-form am-form-horizontal"
							th:action="addMedicine" method="post">

							<div class="am-form-group">
								<label for="name" class="am-u-sm-3 am-form-label">
									药品名称</label>
								<div class="am-u-sm-9">
									<input type="text" id="name" required
										placeholder="药品名称" name="medicine.name">
										<small>10字以内...</small>
								</div>
							</div>

							<div class="am-form-group">
								<label for="user-intro" class="am-u-sm-3 am-form-label">
								库存数量</label>
								<div class="am-u-sm-9">
									<input type="text" id="number" required
										placeholder="库存数量" name="inventory.inventory">
								</div>

							</div>

							<div class="am-form-group">
								<label for="user-intro" class="am-u-sm-3 am-form-label">
									药品单位</label>
								<div class="am-u-sm-9">
									<input type="text" required
										   placeholder="如：盒，支，片" name="medicine.units">
								</div>
							</div>

							<div class="am-form-group">
								<label for="user-intro" class="am-u-sm-3 am-form-label">
									药品规格</label>
								<div class="am-u-sm-9">
									<input type="text" required
										   placeholder="例;0.25g*6片" name="medicine.specification">
								</div>
							</div>

							<div class="am-form-group">
								<label for="user-intro" class="am-u-sm-3 am-form-label">
									药品进价</label>
								<div class="am-u-sm-9">
									<input type="text" required
										   placeholder="单位：元" name="medicine.purchasePrice">
								</div>
							</div>

							<div class="am-form-group">
								<label for="user-intro" class="am-u-sm-3 am-form-label">
									药品售价</label>
								<div class="am-u-sm-9">
									<input type="text" required
										   placeholder="单位：元" name="medicine.salePrice">
								</div>
							</div>

							<div class="am-form-group">
								<label for="user-intro" class="am-u-sm-3 am-form-label">
									备注</label>
								<div class="am-u-sm-9">
									<textarea class="" rows="5" id="user-intro" name="remark"
										placeholder="输入备注"></textarea>
									<small>250字以内...</small>
								</div>
							</div>
							<div class="am-form-group">
								<div class="am-u-sm-9 am-u-sm-push-3">
									<input type="submit" class="am-btn am-btn-success" value="添加药品" />
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		
		</div>
		<!-- content end -->
	</div>
							<!--添加 end-->
								</div>>
						</ul>
					</div>
				</div>
				<!--tab end-->

			</div>

			
			 <script src="js/jquery-1.7.2.min.js" th:href="@{/js/jquery-1.7.2.min.js}" type="text/javascript"></script>
              <script src="js/plugs/Jqueryplugs.js" th:href="@{/js/plugs/Jqueryplugs.js}" type="text/javascript"></script>
              <script src="js/_layout.js" th:href="@{/js/_layout.js}"></script>
             <script src="js/plugs/jquery.SuperSlide.source.js" th:href="@{/js/plugs/jquery.SuperSlide.source.js}"></script>
			<script>
				var num = 1;
				$(function() {

				 $(".tabs").slide({ trigger: "click" });

				});

	
				// var btn_save = function() {
				// 	var pid = $("#RawMaterialsTypePageId  option:selected").val();
				// 	var name = $("#RawMaterialsTypeName").val();
				// 	var desc = $("#RawMaterialsTypeDescription").val();
				// 	var ramark = $("#Ramark").val();
				// 	$.ajax({
				// 		type: "post",
				// 		url: "/RawMaterialsType/AddRawMaterialsType",
				// 		data: { name: name, pid: pid, desc: desc, ramark: ramark },
				// 		success: function(data) {
				// 			if(data > 0) {
				// 				$.jq_Alert({
				// 					message: "添加成功",
				// 					btnOktext: "确认",
				// 					dialogModal: true,
				// 					btnOkClick: function() {
				// 						//$("#RawMaterialsTypeName").val("");
				// 						//$("#RawMaterialsTypeDescription").val("");
				// 						//$("#Ramark").val("");
				// 						//page1();
				// 						location.reload();
				//
				// 					}
				// 				});
				// 			}
				// 		}
				// 	});
				// 	alert(t);
				// }

				var btn_edit = function(obj) {
				    var inventory=$("#inventory").val();
				    if (inventory<=0)
				        alert("库存数量不能小于0");
				    else {
                        var medicine_id=$(obj).attr("data");
                        $.ajax({
                            url:"/editInventory",
                            data:{"medicine_id":medicine_id,"inventory":inventory},
                            type:"post",
                            success:function () {
                                window.location.reload()
                            }
                        })
					}

				}

				// var btn_delete = function(id) {
				// 	$.jq_Confirm({
				// 		message: "您确定要删除吗?",
				// 		btnOkClick: function() {
				// 			var medicine_id=$('#delete').attr("data");
				// 			$.ajax({
				// 			    url:"/deleteMedicine",
				// 				data:{"medicine_id":medicine_id},
				// 				type:"post",
				// 		})
				// 		}
				// 	});
				// }

                $(document).on("click",".btn-delete",function(){
                    var medicine_id=$(this).attr("data");
                    $.jq_Confirm({
                        		message: "您确定要删除吗?",
                        		btnOkClick: function() {
                        			$.ajax({
                        			    url:"/deleteMedicine",
                        				data:{"medicine_id":medicine_id},
                        				type:"post",
										success:function () {
											window.location.reload()
                                        }
                        		})
                        		}
                        	})
				})

			</script>

		</div>
	</body>

</html>